home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / spriteInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-19  |  7.7 KB  |  286 lines

  1. /*-
  2.  * spriteInit.c --
  3.  *    Initialization functions for screen/keyboard/mouse, etc.
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  *
  16.  */
  17. #ifndef lint
  18. static char rcsid[] =
  19. "$Header: /mic/X11R3/src/cmds/Xsp/ddx/sprite/RCS/spriteInit.c,v 1.8 89/11/18 20:57:30 tve Exp $ SPRITE (Berkeley)";
  20. #endif lint
  21.  
  22. #include    "spriteddx.h"
  23. #include    <servermd.h>
  24. #include    "opaque.h"
  25.  
  26. extern void spriteMouseProc();
  27. extern void spriteKbdProc();
  28. extern Bool spriteBW2Probe();
  29. extern Bool spriteCG4Probe();
  30. extern Bool spriteCG6Probe();
  31.  
  32. extern GCPtr CreateScratchGC();
  33.  
  34.     /* What should this *really* be? */
  35. #define MOTION_BUFFER_SIZE 0
  36.  
  37. /*
  38.  * Data describing each type of frame buffer. The probeProc is called to
  39.  * see if such a device exists and to do what needs doing if it does. devName
  40.  * is the expected name of the device in the file system. Note that this only
  41.  * allows one of each type of frame buffer. This may need changing later.
  42.  */
  43. static struct {
  44.     Bool    (*probeProc)();
  45. } spriteFbData[] = {
  46.     spriteBW2Probe, spriteCG4Probe, spriteCG6Probe,
  47. };
  48.  
  49. /*
  50.  * NUMSCREENS is the number of supported frame buffers (i.e. the number of
  51.  * structures in spriteFbData which have an actual probeProc).
  52.  */
  53. #define NUMSCREENS (sizeof(spriteFbData)/sizeof(spriteFbData[0]))
  54. #define NUMDEVICES 2
  55.  
  56. fbFd    spriteFbs[NUMSCREENS];  /* Space for descriptors of open frame buffers */
  57.  
  58. static PixmapFormatRec    formats[] = {
  59.     1, 1, BITMAP_SCANLINE_PAD,    /* 1-bit deep */
  60.     8, 8, BITMAP_SCANLINE_PAD,    /* 8-bit deep */
  61. };
  62. #define NUMFORMATS    sizeof(formats)/sizeof(formats[0])
  63.  
  64. /*-
  65.  *-----------------------------------------------------------------------
  66.  * InitOutput --
  67.  *    Initialize screenInfo for all actually accessible framebuffers.
  68.  *    I kept this like the sun version just because you never know when
  69.  *    support for multiple video devices might be added to Sprite...
  70.  *
  71.  * Results:
  72.  *    screenInfo init proc field set
  73.  *
  74.  * Side Effects:
  75.  *    None
  76.  *
  77.  *-----------------------------------------------------------------------
  78.  */
  79.  
  80. InitOutput(screenInfo, argc, argv)
  81.     ScreenInfo       *screenInfo;
  82.     int           argc;
  83.     char          **argv;
  84. {
  85.     int           i, index;
  86.  
  87.     screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  88.     screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  89.     screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  90.     screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  91.  
  92.     screenInfo->numPixmapFormats = NUMFORMATS;
  93.     for (i=0; i< NUMFORMATS; i++)
  94.     {
  95.         screenInfo->formats[i] = formats[i];
  96.     }
  97.  
  98.     for (i = 0, index = 0; i < NUMSCREENS; i++) {
  99.     if ((*spriteFbData[i].probeProc) (screenInfo, index, i, argc, argv)) {
  100.         /* This display exists OK */
  101.         index++;
  102.     } else {
  103.         /* This display can't be opened */
  104.         ;
  105.     }
  106.     }
  107.     if (index == 0)
  108.     FatalError("Can't find any displays\n");
  109.  
  110.     spriteInitCursor();
  111. }
  112.  
  113. /*-
  114.  *-----------------------------------------------------------------------
  115.  * InitInput --
  116.  *    Initialize all supported input devices...what else is there
  117.  *    besides pointer and keyboard?
  118.  *    NOTE: InitOutput must have already been called.
  119.  *
  120.  * Results:
  121.  *    None.
  122.  *
  123.  * Side Effects:
  124.  *    Two DeviceRec's are allocated and registered as the system pointer
  125.  *    and keyboard devices.
  126.  *
  127.  *-----------------------------------------------------------------------
  128.  */
  129. /*ARGSUSED*/
  130. InitInput(argc, argv)
  131.     int        argc;
  132.     char    **argv;
  133. {
  134.     DevicePtr p, k;
  135.     static int  zero = 0;
  136.     
  137.     p = AddInputDevice(spriteMouseProc, TRUE);
  138.  
  139.     k = AddInputDevice(spriteKbdProc, TRUE);
  140.  
  141.     RegisterPointerDevice(p, MOTION_BUFFER_SIZE);
  142.     RegisterKeyboardDevice(k);
  143.  
  144.     spriteCheckInput = 0;
  145.     SetInputCheck (&zero, &spriteCheckInput);
  146.  
  147.     screenInfo.screen[0].blockData =
  148.     screenInfo.screen[0].wakeupData = (pointer)k;
  149. }
  150.  
  151. /*-
  152.  *-----------------------------------------------------------------------
  153.  * spriteQueryBestSize --
  154.  *    Supposed to hint about good sizes for things.
  155.  *
  156.  * Results:
  157.  *    Perhaps change *pwidth (Height irrelevant)
  158.  *
  159.  * Side Effects:
  160.  *    None.
  161.  *
  162.  *-----------------------------------------------------------------------
  163.  */
  164. /*ARGSUSED*/
  165. void
  166. spriteQueryBestSize(class, pwidth, pheight)
  167.     int            class;    /* Object class being queried */
  168.     short         *pwidth;    /* Width of object */
  169.     short         *pheight;    /* Height of object */
  170. {
  171.     unsigned int  width,
  172.           test;
  173.  
  174.     switch(class) {
  175.       case CursorShape:
  176.       case TileShape:
  177.       case StippleShape:
  178.       width = *pwidth;
  179.       if (width > 0) {
  180.           /*
  181.            * Return the closes power of two not less than what they gave
  182.            * me
  183.            */
  184.           test = 0x80000000;
  185.           /*
  186.            * Find the highest 1 bit in the width given
  187.            */
  188.           while(!(test & width)) {
  189.          test >>= 1;
  190.           }
  191.           /*
  192.            * If their number is greater than that, bump up to the next
  193.            *  power of two
  194.            */
  195.           if((test - 1) & width) {
  196.          test <<= 1;
  197.           }
  198.           *pwidth = test;
  199.       }
  200.       /*
  201.        * We don't care what height they use
  202.        */
  203.       break;
  204.     }
  205. }
  206.  
  207. /*-
  208.  *-----------------------------------------------------------------------
  209.  * spriteScreenInit --
  210.  *    Things which must be done for all types of frame buffers...
  211.  *    Should be called last of all.
  212.  *
  213.  * Results:
  214.  *    None.
  215.  *
  216.  * Side Effects:
  217.  *    The graphics context for the screen is created. The CreateGC,
  218.  *    CreateWindow and ChangeWindowAttributes vectors are changed in
  219.  *    the screen structure.
  220.  *
  221.  *-----------------------------------------------------------------------
  222.  */
  223. void
  224. spriteScreenInit (pScreen)
  225.     ScreenPtr      pScreen;
  226. {
  227.     fbFd          *fb;
  228.     DrawablePtr      pDrawable;
  229.     BITS32        junk;
  230.  
  231.     fb = &spriteFbs[pScreen->myNum];
  232.  
  233.     /*
  234.      * We need a GC for the cursor functions. We also don't want to
  235.      * have to allocate one each time. Note that it is allocated before
  236.      * CreateGC is intercepted so there are no extra indirections when
  237.      * drawing the cursor...
  238.      */
  239.     fb->pGC = CreateScratchGC (pScreen, pScreen->rootDepth);
  240.     fb->pGC->graphicsExposures = FALSE;
  241.     
  242.     /*
  243.      * Preserve the "regular" functions
  244.      */
  245.     fb->CreateGC =                    pScreen->CreateGC;
  246.     fb->CreateWindow =                     pScreen->CreateWindow;
  247.     fb->ChangeWindowAttributes =        pScreen->ChangeWindowAttributes;
  248.     fb->GetImage =                    pScreen->GetImage;
  249.     fb->GetSpans =                    pScreen->GetSpans;
  250.  
  251.     /*
  252.      * Interceptions
  253.      */
  254.     pScreen->CreateGC =                    spriteCreateGC;
  255.     pScreen->CreateWindow =             spriteCreateWindow;
  256.     pScreen->ChangeWindowAttributes =     spriteChangeWindowAttributes;
  257.     pScreen->QueryBestSize =            spriteQueryBestSize;
  258.     pScreen->GetImage =                    spriteGetImage;
  259.     pScreen->GetSpans =                    spriteGetSpans;
  260.  
  261.     /*
  262.      * Cursor functions
  263.      */
  264.     pScreen->RealizeCursor =             spriteRealizeCursor;
  265.     pScreen->UnrealizeCursor =            spriteUnrealizeCursor;
  266.     pScreen->DisplayCursor =             spriteDisplayCursor;
  267.     pScreen->SetCursorPosition =        spriteSetCursorPosition;
  268.     pScreen->CursorLimits =             spriteCursorLimits;
  269.     pScreen->PointerNonInterestBox =     spritePointerNonInterestBox;
  270.     pScreen->ConstrainCursor =             spriteConstrainCursor;
  271.     pScreen->RecolorCursor =             spriteRecolorCursor;
  272.  
  273.     /*
  274.      * Set pixel values for sun's view of the world...
  275.      */
  276.     pScreen->whitePixel = 0;
  277.     pScreen->blackPixel = 1;
  278.  
  279.     /*
  280.      *    Block/Unblock handlers
  281.      */
  282.     screenInfo.screen[0].BlockHandler = spriteBlockHandler;
  283.     screenInfo.screen[0].WakeupHandler = spriteWakeupHandler;
  284. }
  285.  
  286.